package com.summer.core.web.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.summer.core.service.impl.BaseServiceImpl;
import com.summer.core.web.bean.Menu;
import com.summer.core.web.dao.MenuDao;
import com.summer.core.web.service.MenuService;
/**
 * 菜单service实现 
 * @author wwwlike
 *
 */
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu, String, MenuDao>
		implements MenuService {

	@Resource
	public void setDao(MenuDao dao) {
		this.dao = dao;
	}

	public List<Set<Menu>> getAllSubMenu(String pid) {
		List<Set<Menu>> menuList=new ArrayList<Set<Menu>>();
	
		Set<Menu> set=load(pid).getChildren();
		 Iterator<Menu> iterator = set.iterator();
		 
		  while (iterator.hasNext()){
			Menu menu=iterator.next();
			Set<Menu> sub=load(menu.getId()).getChildren();
			menuList.add(sub);
		  }
		return menuList;
	}

	public Set<Menu> getSubMenu(String pid) {
		Set<Menu> set=load(pid).getChildren();
		return set;
	}

	
	public void addTableMenu(String table_id,String title, String pid) {
		Menu menu=new Menu();
		//暂时放在这个下面
		Menu Parent=load("5");
		menu.setParent(Parent);
		String k=save(menu);
		menu.setTitle(title);
		menu.setUrl("admin/table!index.action?id="+table_id);
		update(menu);
	}
	
	
}
